Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = _default;

var _api = _interopRequireDefault(require("../../../../utils/api")), _util = _interopRequireDefault(require("../../../../public/utils/util"));

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var RANK = {
    newuser: "客户总数",
    view: "浏览次数",
    transfer: "转发次数",
    fav: "保存次数",
    like: "点赞人数",
    contact: "沟通人数"
}, RANK_KEYS = Object.keys(RANK), RANK_TYPE = RANK_KEYS.map(function(t) {
    return RANK[t];
}), LIMIT = 20;

function _default() {
    var r, u = 0, d = !1;
    return {
        init: function(t) {
            (r = t).setData({
                rankIndex: 0,
                RANK_TYPE: RANK_TYPE,
                rankList: []
            });
        },
        onPullDownRefresh: function() {
            this.loadData(!0, wx.stopPullDownRefresh);
        },
        onReachBottom: function() {
            d || this.loadData();
        },
        changeRankIndex: function(t) {
            r.setData({
                rankIndex: t
            }), this.loadData(!0);
        },
        gotoSingleView: function(t) {
            var a = r.data, e = a.rankList, n = a.card, i = getCurrentPages()[0];
            i.$put("card.data", Object.assign({
                guid: n.guid
            }, e[t])), i.$route("/pages/radar/singleuser/singleuser");
        },
        loadData: function(e, t) {
            e && (u = 0);
            var a = r.data, n = a.rankIndex, i = a.department;
            _api.default.minicard.analysis.rank({
                loading: !0,
                data: {
                    guid: r.data.card.guid,
                    type: RANK_KEYS[n],
                    limit: LIMIT,
                    offset: u,
                    catid: i.catid
                },
                complete: t
            }).then(function(t) {
                var a = _util.default.addThumbToList(t.data.list);
                e || (a = r.data.rankList.concat(a)), r.setData({
                    rankList: a
                }), d = a.length < LIMIT, u += LIMIT;
            });
        }
    };
}